import axios from '@/axios'
//登录
export function login(username, password) {
    return axios.post('/admin/login', {
        username: username,
        password: password
    });
}

//获取用户信息
export function getInfo()
{
    return axios.post('/admin/getinfo');
}

//退出登录
export function logout()
{
    return axios.post('/admin/logout');
}

//修改密码
export function repassword(data)
{
    return axios.post('/admin/updatepassword',data);
}

//获取管理员信息
export function getManagerlist(page=1,querry={})
{
    let q = [];
    for (const key in querry)
    {
        if (querry[key])
        {
            q.push(`${key}=${encodeURIComponent(querry[key])}`);    
        }
    }

    let r = q.join('&');
    r = r ? ("?" + r) : "";
    return axios.get(`/admin/manager/${page}${r}`);
}

//修改管理员的状态栏
export function changeStatus(id,status)
{
    return axios.post(`/admin/manager/${id}/update_status`, { status });
}

//删除管理员
export function deleteManager(id)
{
    return axios.post(`/admin/manager/${id}/delete`);
}

//修改管理员
export function changeManager(id,data)
{
    return axios.post(`/admin/manager/:id`,data);
}

//新增管理员
export function addManager(data)
{
    return axios.post("/admin/manager", data);
}

